package se.hh.service;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.InstrumentsDao;
import se.hh.lab.dao.impl.InstrumentsDaoImpl;
import se.hh.lab.domain.Instruments;

public class QueryAdvancedInstruments extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		this.doPost(req, resp);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{			
		String name=request.getParameter("name");
		String type=request.getParameter("type");
		String barcode=request.getParameter("barcode");			
		Integer page=Integer.parseInt(request.getParameter("page"));
		Integer intPage=page;
		if(intPage==0)
			intPage=1;
		request.setAttribute("name", name);
		request.setAttribute("type", type);
		request.setAttribute("barcode",barcode);
		request.setAttribute("intPage", intPage);
		HttpSession session=request.getSession();
		if(barcode==null &&page==null)
		{
			response.sendRedirect("user_main.jsp");
			return;
		}
		else
		{
			InstrumentsDao instruDao=new InstrumentsDaoImpl();
			Instruments instru=new Instruments();
			instru.setBarcode(barcode);
			instru.setName(name);
			instru.setType(type);
			ArrayList<Instruments> list=instruDao.getAdvancedInstruments(instru,intPage);
			session.setAttribute("list", list);
			request.getRequestDispatcher("user_queryInstrument.jsp").forward(request, response);

		
		}
	}

}
